package com.cyt.dao.impl;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.cyt.entity.ShangPingXX;
import com.cyt.util.DBManager;
//产品分类页面的搜索 模糊查询 返回集合 且带参数 name前台传回的值
public class ShangPingSouSuoDaoImpl {
	public List<ShangPingXX> getShangPingSuo(String name ) {//一般看sql语句有没有条件
		List <ShangPingXX> list = new ArrayList<ShangPingXX>();
		Statement st = null;
		ResultSet rs = null;
		// 1.建立连接
		Connection conn = DBManager.getConnection();
		// 2.创建Statement执行对象(用来执行sql语句)
		try {// try 正常执行
			st = conn.createStatement();
			// 3.sql语句
			String sql = "SELECT * FROM shangping where cPName like  '%"+name+"%'";
			// 4.执行sql语句,返回结果集
			rs = st.executeQuery(sql);
			// 5. 遍历结果集
			while (rs.next()) { 
				int cPid = rs.getInt("cPid");
				String cPName = rs.getString("cPName");
				String cPCaiZhi = rs.getString("cPCaiZhi");
				String cPPingPai = rs.getString("cPPingPai");
				String xingHao = rs.getString("xingHao");
				String yanSe = rs.getString("yanSe");
				String dingZhi = rs.getString("dingZhi");
				String chuanYiRenQun = rs.getString("chuanYiRenQun");
				int cPShoujia = rs.getInt("cPShoujia");
				int cPShiChangSJ = rs.getInt("cPShiChangSJ");
				int fengLeiId = rs.getInt("fengLeiId");
				String cPImg = rs.getString("cPImg");
				ShangPingXX spxxSS = new ShangPingXX(cPid, cPName, cPCaiZhi, cPShoujia, cPShiChangSJ, cPPingPai, xingHao, yanSe, dingZhi, chuanYiRenQun, fengLeiId, cPImg);// 创建用户对象
				list.add(spxxSS);// 把user对象存入list中
			}
			return list;// 正常情况返回集合
         
		} catch (SQLException e) {// catch 异常执行
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;// 异常返回空
		} finally {
			DBManager.closeAll(conn, st, rs);
		}

	}

}
